package com.qf.utils;

//import cn.hutool.core.date.DateUtil;
//import com.auth0.jwt.JWT;
//import com.auth0.jwt.algorithms.Algorithm;

import javax.servlet.http.HttpServletRequest;
import java.util.Calendar;
import java.util.HashMap;
import java.util.Map;
import java.util.Set;

public class Utils {

    //生成jwt
//    public static String jwtGenerate(String id,String pass){
//        //设置载体
//        String sign = JWT.create().withAudience(id, pass)
//                //设置过期时间：工具类hutool---DateUtil.offsetHour(当前时间Date，int)
//                .withExpiresAt(DateUtil.offsetHour(Calendar.getInstance().getTime(), 1))
//                //加算方式
//                .sign(Algorithm.HMAC256(pass));
//        return sign;
//    }




    // 将request中的参数转换成Map
    public static Map<String, String> convertRequestParamsToMap(HttpServletRequest request) {
        Map<String, String> retMap = new HashMap<String, String>();

        //将请求中的键值信息转换为set存储
        Set<Map.Entry<String, String[]>> entrySet = request.getParameterMap().entrySet();

        //将请求中所有键值集合遍历
        for (Map.Entry<String, String[]> entry : entrySet) {
            String name = entry.getKey();
            String[] values = entry.getValue();
            int valLen = values.length;

            if (valLen == 1) {
                retMap.put(name, values[0]);
            } else if (valLen > 1) {
                StringBuilder sb = new StringBuilder();
                for (String val : values) {
                    sb.append(",").append(val);
                }
                retMap.put(name, sb.toString().substring(1));
            } else {
                retMap.put(name, "");
            }
        }

        return retMap;
    }


}
